package cz.semjob.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TextUtil {
	
	public static int countTextOccurences(String text, String pattern, int from, int to) {
		text = text.substring(from, to);
	    Pattern p = Pattern.compile(pattern, Pattern.MULTILINE);
	    
	    Matcher m = p.matcher(text);
	    int count = 0;
	    while (m.find()){
	    	count +=1;
	    }
		return count;
	}
	
	public static int getLastOccurenceEndIndex(String text, String pattern, int from, int to) {
		text = text.substring(from, to);
		  Pattern p = Pattern.compile(pattern, Pattern.MULTILINE);
		    int end = 0;
		    Matcher m = p.matcher(text);
		    while (m.find()){
		    	end = m.end();
		    }
		    
			return from + end;
	}

}
